package com.itheima.ydd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.Menu;
import com.itheima.ydd.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Copyright (C), 2021-2022
 * Author: 16372
 * Date: 2022/2/26 16:07
 * FileName: MenuController
 * Description: 菜单管理
 */
@RestController
@Slf4j
@RequestMapping("/sys_menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * @return com.itheima.ydd.common.ResultData
     * @Author 16372
     * @Description //TODO 菜单列表展示
     * @Date 16:56 2022/2/26
     * @Param []
     **/
    @GetMapping("/allData")
    public ResultData getAll() {
        List<Menu> menuList = menuService.selectAll(null);
        return ResultData.ok("", menuList);
    }

    /**
     * @return com.itheima.ydd.common.ResultData
     * @Author 16372
     * @Description //TODO 菜单修改
     * @Date 16:58 2022/2/26
     * @Param [menu]
     **/
    @PostMapping("/update")
    public ResultData update(@RequestBody Menu menu) {
        menuService.updateById(menu);
        return ResultData.ok("", "");
    }

    /**
     * @return com.itheima.ydd.common.ResultData
     * @Author 16372
     * @Description //TODO 根据id删除
     * @Date 16:59 2022/2/26
     * @Param [id]
     **/
    @GetMapping("/del")
    public ResultData del(Integer id) {
        menuService.removeById(id);
        return ResultData.ok("", "");
    }

    /**
     * @Author 16372
     * @Description //TODO 添加菜单
     * @Date 17:07 2022/2/26
     * @Param [menu]
     * @return com.itheima.ydd.common.ResultData
     **/
    @PostMapping("/add")
    public ResultData add(@RequestBody Menu menu) {

        menuService.save(menu);
        return ResultData.ok("", "");
    }

    /**
     * @Author 16372
     * @Description //TODO 查看菜单详情
     * @Date 17:07 2022/2/26
     * @Param [id]
     * @return com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/rowInfo")
    public ResultData rowInfo(Integer id){
        Menu menu = menuService.getById(id);
        return ResultData.ok("",menu);
    }

}
